package tgc.edu.szxt.demo.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.szxt.demo.custom.BaseEntity;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class SysDept extends BaseEntity<Integer>{
	private String name;
	@JsonIgnore
	private SysDept parent;
	@JsonIgnore
	private List<SysDept> chilren= new ArrayList<>();
	private String idx1;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToOne
	public SysDept getParent() {
		return parent;
	}
	public void setParent(SysDept parent) {
		this.parent = parent;
	}
	
	@Transient
	public Integer getParentId() {
		return parent==null?null:parent.getId();
	}
	@OneToMany(cascade = CascadeType.ALL,mappedBy = "parent")
	@OrderBy(value = "idx1")
	public List<SysDept> getChilren() {
		return chilren;
	}
	public String getIdx1() {
		return idx1;
	}
	public void setIdx1(String idx1) {
		this.idx1 = idx1;
	}
	public void setChilren(List<SysDept> chilren) {
		this.chilren = chilren;
	}
	
	
}
